﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductDetail.aspx.cs"
    ValidateRequest="false" Inherits="Habito.Admini.ProductDetail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"><title>ProductDetail</title>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/kindeditor-all-min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="../Scripts/common.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/kindeditor_zh_cn.js"></script>
    <link rel="stylesheet" href="../../Content/kindeditor_default/default.css" />
    <script type="text/javascript">
        $(function () {
            //上传图片
            $("#btnUpload").click(function () {
                if ($("#flUpload").val() == "") {
                    alert("请选择一个图片文件，再点击上传。");
                    return;
                }
                $('#UpLoadForm').ajaxSubmit({
                    success: function (html, status) {
                        html = html.replace("<pre>", "");
                        html = html.replace("</pre>", "");
                        html = html.replace("<PRE>", "");
                        html = html.replace("</PRE>", "");
                        $("#image").attr('src', '..' + html);
                        $("#imageName").val('..' + html);
                        alert(html);
                    }
                });
            });
        });
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="Content"]', {
                resizeType: 1,
                allowPreviewEmoticons: true,
                allowImageUpload: true,
                allowFileManager: true,
                allowUpload: true,
                uploadJson: "../Admini/upload_json.ashx",
                fileManagerJson: '../Admini/file_manager_json.ashx',
                items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
						'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
						'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
						'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
						'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
						'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
						 'table', 'hr', 'pagebreak',
						'anchor', 'link', 'unlink', '|', 'about']
            });
        });

        $(document).ready(function () {
            var id = $("#pID").val();
            if (id != "0") {
                // get productmsg
                $.ajax({
                    url: window.location.href + "&GetProductByID=1",
                    data: {},
                    cache: false,
                    success: function (data) {
                        data = $.evalJSON(data);
                        if (data != undefined) {
                            $("#id").val(data.ID);
                            $("#productClass").val(data.ClassID);
                            $("#productName").val(data.ProductName);
                            $("#showIndex").val(data.ShowIndex);
                            $("#imageName").val(data.ImagePath);
                            $("#image").attr("src", data.ImagePath);
                            editor.insertHtml(data.Description);
                            $("#showInClass").val(data.ShowInClass);
                        }
                    },
                    error: function (data) {
                    }
                });
            }
            else {
                $("#productClass").val($("#classID").val());
            }
        });

        function save() {
            var id = $("#id").val();
            if (id == "") {
                id = 0;
            }
            var classid = parseInt($("#productClass").val());
            var productName = $("#productName").val();
            var showindex = parseInt($("#showIndex :selected").val());
            var description = escape(editor.html());
            var imagePath = $("#imageName").val();
            var showInClass = parseInt($("#showInClass :selected").val());
            $.ajax({
                url: window.location.href + "&SaveProduct=1",
                //processData: false, 
                type: 'post',
                //data: "ShowIndex=" + showindex,
                data: "ShowIndex=" + showindex + "&ShowIndexClass=" + showInClass + "&productName=" + productName + "&description=" + description + "&imagePath=" + imagePath,
                success: function (data) {
                    alert("Save Success");
                    location.href("Product.aspx");
                },
                error: function (data) {
                    alert();
                }
            });
        }
    </script>
</head>
<body>
    <input type="hidden" name="name" id="uploaded" value="<%=ViewState["uploaded"]  %>" />
    <input type="hidden" name="name" id="pID" value="<%=ViewState["id"] %>" />
    <input type="hidden" name="name" id="classID" value="<%=ViewState["classID"]  %>" />
    <div>
        <div>
            <input type="hidden" name="" value="" id="id" />
            <input type="text" name="" value="" id="productClass" readonly="readonly" style="display: none" />
            Product Name:<input type="text" name="" value="" id="productName" />
            <input type="hidden" name="" value="" id="classid" />
            ShowInIndex:<select id="showIndex">
                <option value="0">No</option>
                <option value="1">Yes</option>
            </select>
            <%--	<img src="../upload/images/products/HABITO PC-106L.jpg" alt="Alternate Text" />--%>
			ShowInClass:<select id="showInClass">
                <option value="0">No</option>
                <option value="1">Yes</option>
            </select>
            <br />
            <form id="UpLoadForm" name="UpLoadForm" method="post" enctype="multipart/form-data"
                action="../PicUploadHander.ashx">
                <table border="0" cellpadding="0" cellspacing="0" class="upp">
                    <tr>
                        <td>
                            <img id="image" style="width: 150px; height: 100px;" />
                            <input type="file" id="flUpload" name="flUpload" />Image size:80px*150px(H*L)
							<input id="btnUpload" type="button" value="上传" />
                        </td>
                    </tr>
                </table>
            </form>
            <input type="button" name="" value="Save" onclick="save()" />
            <input type="button" name="" value="Cancel" onclick="cancel()" />
            <input type="hidden" name="" value="" runat="Server" id="imageName" />
        </div>
        <textarea id="txtContent" name="Content" cols="80" rows="40"></textarea></div>
</body>
</html>
